import { Minute } from "../配置/基础配置";

export function Main(Npc: TNormNpc, Player: TPlayObject, Args: TArgs) {
    let y = 0
    let ItemsString = ``;

    ItemsString += `<{S=挂机时每${Player.V.RandomTime || 0}分钟随机一次;C=255;X=0;Y=${y}}>`
    ItemsString += `<{S=设置;C=251;X=250;Y=${y};/@@挂机.InputString1(请输入随机时间3-60)}>`
    y += 15

    Npc.Say(Player, ItemsString)
}

export function InputString1(Npc: TNormNpc, Player: TPlayObject, Args: TArgs) {
    let num = Args.Int[0];
    if (num < 3) {
        num = 0;
    }
    num = Math.min(num, 60)
    Player.V.RandomTime = num;
    Main(Npc, Player, Args)
}

export function 开始挂机(Player: TPlayObject) {
    Player.R.lastRandomTime = GameLib.TickCount;
    Player.R.isAutoFight = true
    // Player.SetThroughMonster(true)
}
export function 结束挂机(Player: TPlayObject) {
    Player.R.isAutoFight = false
    // Player.SetThroughMonster(false)
}
export function 挂机执行(Player: TPlayObject) {
    if (Player.R.isAutoFight && Player.V.RandomTime > 0) {
        let time = GameLib.TickCount - Player.R.lastRandomTime
        if (time >= Player.V.RandomTime * Minute) {
            Player.R.lastRandomTime = GameLib.TickCount;
            // console.log(`随机前:${Player.MapX}  ${Player.MapY}`)
            Player.RandomMove(Player.Map.MapID);
            // console.log(`随机后:${Player.MapX}  ${Player.MapY}`)
        }
    }
}